package interfaces;

import java.util.Random;

interface Game {
    void play();
}

class DiceGame implements Game {

    private Random random = new Random();

    @Override
    public void play() {
        System.out.println("掷骰子游戏： 你得到的点数是 " + (random.nextInt(6) + 1));
    }
}

class CoinGame implements Game {

    private Random random = new Random();

    @Override
    public void play() {
        System.out.println("抛硬币游戏： 你得到的是 " + (random.nextBoolean() ? "正面" : "反面"));
    }
}

class DiceGameFactory implements GameFactory {

    @Override
    public Game getGame() {
        return new DiceGame();
    }
}

class CoinGameFactory implements GameFactory {

    @Override
    public Game getGame() {
        return new CoinGame();
    }
}

interface GameFactory {
    Game getGame();
}



/**
 * 抛硬币和掷骰子
 */
public class GameDemo {
    static void playGames(GameFactory factory) {
        factory.getGame().play();
    }

    public static void main(String[] args) {
        playGames(new DiceGameFactory());
        playGames(new CoinGameFactory());
    }
}
